package com.group.project.hrms.service.impl;

import com.group.project.hrms.entity.FrontLineVacationRecord;
import com.group.project.hrms.mapper.FrontLineVacationRecordMapper;
import com.group.project.hrms.service.IFrontLineVacationRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.List;

@Service
public class FrontLineVacationRecordService implements IFrontLineVacationRecordService {

    @Autowired
    private FrontLineVacationRecordMapper frontLineVacationRecordMapper;


    @Override
    public int insertFrontLineVacationRecord(FrontLineVacationRecord frontLineVacationRecord) {
        return frontLineVacationRecordMapper.insert(frontLineVacationRecord);
    }

    @Override
    public int deleteFrontLineVacationRecord(FrontLineVacationRecord frontLineVacationRecord) {
        return frontLineVacationRecordMapper.deleteByPrimaryKey(frontLineVacationRecord);
    }

    @Override
    public int updateFrontLineVacationRecord(FrontLineVacationRecord frontLineVacationRecord) {
        return frontLineVacationRecordMapper.updateByPrimaryKey(frontLineVacationRecord);
    }

    @Override
    public FrontLineVacationRecord selectOneFrontLineVacationRecord(FrontLineVacationRecord frontLineVacationRecord) {
        return frontLineVacationRecordMapper.selectByPrimaryKey(frontLineVacationRecord);
    }

    @Override
    public FrontLineVacationRecord selectFrontLineVacationRecordByFID(String fid) {
        Example example = new Example(FrontLineVacationRecord.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.orEqualTo("fid" , fid);
        return frontLineVacationRecordMapper.selectOneByExample(example);
    }

    @Override
    public List<FrontLineVacationRecord> selectFrontLineVacationRecordByMonth(String month) { //月份的数据结构为：2022-04
        Example example = new Example(FrontLineVacationRecord.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.orLike("cTime", "%" + month + "%");
        return frontLineVacationRecordMapper.selectByExample(example);
    }

    @Override
    public List<FrontLineVacationRecord> selectFrontLineVacationRecordByRangeDate(String dateStart, String dateEnd) {
        Example example = new Example(FrontLineVacationRecord.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.orBetween("startTime", dateStart, dateEnd);
        criteria.orBetween("endTime", dateStart, dateEnd);
        return frontLineVacationRecordMapper.selectByExample(example);
    }

    @Override
    public List<FrontLineVacationRecord> selectFrontLineVacationRecordByRangeCreateDate(String dateStart, String dateEnd) {
        Example example = new Example(FrontLineVacationRecord.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.orBetween("cTime", dateStart, dateEnd);
        return frontLineVacationRecordMapper.selectByExample(example);
    }

    @Override
    public List<FrontLineVacationRecord> selectFrontLineVacationRecordByDateForOneContact(String dateStr) {
        Example example = new Example(FrontLineVacationRecord.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.orLike("startTime", "%" + dateStr + "%");
        criteria.orLike("endTime", "%" + dateStr + "%");
        return frontLineVacationRecordMapper.selectByExample(example);
    }

    @Override
    public List<FrontLineVacationRecord> selectAllFrontLineVacationRecord() {
        return frontLineVacationRecordMapper.selectAll();
    }
}
